<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
	<c:url var="action" value="/ivan" />
	${msg} 
	 <div id ="error">
	 	<h3>${error}</h3>
	 </div>
	
	<c:if test="${msg == -1}">
		<div class = "login">
			<form action="<c:url value='${pageContext.request.contextPath}/j_spring_security_check' />" method="post" class="f-clear" >
			    <label for="j_username">Username :</label>
			    <input name="j_username" id="j_username" type="text" />
			    <label for="j_password">Password : </label>
			    <input type="password" name="j_password" id="password"  />
			    <span id="error-text"></span>
			    <input type="submit" name="action" id="action" value="Login" />
			</form>
		</div>
		<div class = "main">
			<c:forEach items="${messages}" var="message">
				<div class = "main1">	
					<div class = "main2">
				  	 	 <img src = "<c:url value="/images/empty.jpg" />">
					     <c:forEach items="${accounts}" var="account">
				     		<c:if test="${account.accountid eq message.accountid}"> 
							 <span><c:out value="${account.username}" /></span>
						    </c:if>
					     </c:forEach>	
					</div>
					<div class ="main3">  
				     	<p><c:out value="${message.message}" /></p>
				    </div>
				     <div class = "main4">
					    <c:if test="${msg eq message.accountid}"> 
					    </c:if>
					</div>
			  	</div>
			</c:forEach>	
		</div>
	</c:if>	
	
	<c:if test="${msg != -1}">
		<a href = <c:url value="/ivan/logout" /> class="f-left"> Logout </a>
		<div class = "main">
			<c:forEach items="${messages}" var="message">
				<div class = "main1">	
					<div class = "main2">
				  	<img src = "<c:url value="/images/empty.jpg" />">
				    <c:forEach items="${accounts}" var="account">
			     		<c:if test="${account.accountid eq message.accountid}"> 
						  <span>
						  	<c:out value="${account.username}" />
						  </span>
					    </c:if>
			     	</c:forEach>	
					</div>
					<div class ="main3"> 
				   		<p>
				   			<c:out value="${message.message}" />
				   		</p>
				   	</div>
				   	<div class = "main4">
					    <c:if test="${msg eq message.accountid}">  
						   <td>
						     <a class = "top" href="${action}/edit?id=${message.messageid}">Edit</a>
						   </td>
					    </c:if>
					</div>
				</div>
			</c:forEach>
		</div>
		<div class = "msgBody">
			<table>
				<form:form action="${action}/add" method="post" commandName="mensahe">
				    <form:label path="accountid"></form:label>
					<form:input type="hidden" path="accountid" id="accountid" value = "${msg}" />
				    <tr>
				    	<td>
				    		<form:label path="message">Message</form:label>
				    	</td>
				    </tr>
				    <tr>
				    	<td>
				    		<form:textarea path="message" id="message" rows="8" cols = "60"></form:textarea>
				    	</td>
				   	</tr>
				    <tr>
				    	<td>
				    		<input type="submit" name="action2" id="action2" value="Send" />
				    	</td>
				    </tr>
				</form:form>
			</table>
		</div>
	</c:if>	
